package com.nbicc.ad.controller;

import com.nbicc.ad.po.AdCategory;
import com.nbicc.ad.service.IAdCategoryService;
import com.nbicc.common.RequestPageObj;
import com.nbicc.common.ResponseObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;

@Api(value = "广告分类" , description = "广告分类")
@RestController
@RequestMapping(value = "/ad/cat")
public class AdCategoryController {

    @Resource(name = "AdCategoryService")
    private IAdCategoryService adCategoryService;

    @ApiOperation(value = "按id查询广告分类")
    @GetMapping("/id/{id}")
    @ResponseBody
    public ResponseObj selectById(@PathVariable int id) throws Exception {
        AdCategory adCategory = adCategoryService.selectById(id);
        return ResponseObj.success().setResult(adCategory);
    }

    @ApiOperation(value = "添加广告分类")
    @PostMapping
    @ResponseBody
    public ResponseObj insert(@RequestBody AdCategory adCategory) throws  Exception{
        adCategoryService.insert(adCategory);
        return ResponseObj.success().setResult(adCategory);
    }

    @ApiOperation(value = "修改广告分类信息")
    @PutMapping
    @ResponseBody
    public ResponseObj update(@RequestBody Map<String,Object> adCategory) throws Exception{
        adCategoryService.updateById(adCategory);
        return ResponseObj.success();
    }

    @ApiOperation(value = "删除广告分类", notes = "只需包含广告分类id")
    @DeleteMapping("/id/{id}")
    @ResponseBody
    public ResponseObj delete(@PathVariable int id){
        adCategoryService.deleteById(id);
        return ResponseObj.success();
    }

    //↑crud========================================================================

    @ApiOperation(value = "按条件(分页等) 广告分类", notes = "分页和条件查询")
    @PostMapping("/find")
    @ResponseBody
    public ResponseObj find(@RequestBody RequestPageObj<Map<String,Object>> requestPageObj){
        ResponseObj responseObj = adCategoryService.find(requestPageObj);
        return responseObj;
    }

}
